package com.group4.Utility;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mail {
	private String toMail;
	private String subject;
	private String content;

	public Mail(String toMail, String subject, String content) {
		super();
		this.toMail = toMail;
		this.subject = subject;
		this.content = content;
	}

	public String getToMail() {
		return toMail;
	}

	public void setToMail(String toMail) {
		this.toMail = toMail;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void send() {
		String host = "smtp.mandrillapp.com";
		String from = "signportgroup4@gmail.com";
		String pass = "ADJ0U1ShpEHJtO6XbS3NBw";
		Properties props = System.getProperties();
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", host);
		props.put("mail.smtp.user", from);
		props.put("mail.smtp.password", pass);
		props.put("mail.smtp.port", "587");
		props.put("mail.smtp.auth", "true");

		try {
			Session session = Session.getDefaultInstance(props, null);
			MimeMessage message = new MimeMessage(session);
			message.setFrom(new InternetAddress(from));

			InternetAddress toAddress = new InternetAddress();

			toAddress = new InternetAddress(this.toMail);

			message.addRecipient(Message.RecipientType.TO, toAddress);
			message.setSubject(this.subject);

			message.setContent(this.content, "text/html; charset=utf-8");

			Transport transport = session.getTransport("smtp");
			transport.connect(host, from, pass);
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
